﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebService_Newstore.DAO
{
    public class AnomalieDAO: BaseDAO
    {
        public int id;
        public string libelle;

        public AnomalieDAO() { }

        public static List<AnomalieDAO> getAnomaliesList()
        {
            List<AnomalieDAO> listToSend = new List<AnomalieDAO>();

            using (newStoreContext = new newStoreEntities())
            {
                try
                {
                    var query = from Anomalie in newStoreContext.anomalies
                                select Anomalie;

                    if (query.LongCount() == 0)
                        throw new Exception("Erreur, aucune Anomalie trouvée !");

                    foreach (var result in query)
                    {
                        AnomalieDAO AnomalieDAO = new AnomalieDAO();
                        AnomalieDAO.id = result.id_anomalie;
                        AnomalieDAO.libelle = result.lib_anomalie;
                        
                        listToSend.Add(AnomalieDAO);

                    }
                    return listToSend;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    return listToSend;
                }
            }
        }
    }
}